//****************************************************************************
// File:    Card.cpp
// Author:  Dr. Thomas C. Bressoud
// Date:    February 8, 2008
// Class:   CS 173-01, Professor Bressoud
// Purpose: Implementation file for the Card class, defining a single card
//          with a domain consisting of a rank and a suit.  Operations include
//          creation and acessing rank and suit.
// Input:   NA
// Output:  NA
//****************************************************************************

#include "headers.h"

Card::Card()
//============================================================================
// Purpose: Default constructor, initializing a card to the ace of spaces.
//
// Precondition:  None
// Postcondition: Created Card object with valid rank (ace) and suit (spades)
//============================================================================
{
  mySuit = SPADES;
  myRank = 1;
}

Card::Card(int r, Suit s)
//============================================================================
// Purpose: Constructor, initializing a card to the given rank r and suit s.
//
// Precondition:  1 <= r <= 13 && s in {SPADES, HEARTS, DIAMONDS, CLUBS}
// Postcondition: Created Card object with rank r, and suit s
//============================================================================
{
  assert(r >= 1 && r <= 13);
  assert((int)s >= 0 && (int)s <= NUMSUIT);
  
  mySuit = s;
  myRank = r;
}

// Below in this file,
// create the function definitions for remaining function in the Card class:
// 
// int Card::getRank() const
// Card::Suit Card::getSuit() const
// void Card::print() const
// string Card::toString() const


int Card::getRank() const{
    return this -> myRank;
}

Card::Suit Card::getSuit() const{
    return this -> mySuit;
}

string Card::toString() const{
    string s ;
    s = this -> suitString(this->mySuit) + "_" + this -> rankString(this->myRank);

    return s;
}

void Card::print() const{
    cout << this->getRank() << ":" << this->getSuit() << endl;
}

string Card::suitString(Card::Suit s) const{
    switch( s ) {
        case SPADES:
            return "spades";
        case HEARTS:
            return "hearts";
        case DIAMONDS:
            return "diamonds";
        case CLUBS:
            return "clubs";
        default:
            cout << "Wrong Suit!" << endl;
            return "None";
    }
}

string Card::rankString(int r) const{
    switch ( r ) {
        case 1:
            return "ace";
        case 2:
            return "two";
        case 3:
            return "three";
        case 4:
            return "four";
        case 5:
            return "five";
        case 6:
            return "six";
        case 7:
            return "seven";
        case 8:
            return "eight";
        case 9:
            return "nine";
        case 10:
            return "ten";
        case 11:
            return "jack";
        case 12:
            return "queen";
        case 13:
            return "king";
    }
}
